package com.anotherrobbo.armedia.server.console;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import com.anotherrobbo.armedia.engine.PlayerEngine;
import com.anotherrobbo.armedia.server.AbstractReader;

public class ConsoleReader extends AbstractReader {

	public ConsoleReader(PlayerEngine engine) {
		super("ConsoleReader", engine);
	}
	
	public void read() {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		boolean cont = true;
		try {
			while (cont) {
				log.info("Awaiting command...");
				String line = reader.readLine();
				cont = actionInput(line);
			}
			// the exit command on the console kills it all!
			System.exit(1);
		} catch (IOException ioe) {
			log.error("Exception thrown:", ioe);
		} finally {
			try {
				reader.close();
			} catch (IOException ioe) {
				log.error("Unable to close reader:", ioe);
			}
		}
	}
	
}
